
import edu.wpi.first.smartdashboard.gui.Widget;
import edu.wpi.first.smartdashboard.gui.elements.Image;
import edu.wpi.first.smartdashboard.properties.Property;
import edu.wpi.first.smartdashboard.types.DataType;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Franklin
 */
public class CourtWidget extends Widget {
    
        public static final DataType[] TYPES = { DataType.NUMBER };
        private short x = 0;
        private short y = 0;
        BufferedImage  mCourt;

        
        @Override
    public void setValue(Object value) {
        this.x = (short)(((Number) value).intValue()&0x0000ffff);
        this.y = (short)((((Number) value).intValue()&0xffff0000)>>16);
        repaint();
    }
        
    @Override
    public void init() {
        setPreferredSize (new Dimension(206,412));
        try {
            mCourt=ImageIO.read(new File("/court3.jpg"));
            assert(mCourt!=null);
        } catch (IOException ex) {
            Logger.getLogger(CourtWidget.class.getName()).log(Level.SEVERE, null, ex);
        }
 
    }

    @Override
    public void propertyChanged(Property property) {

    }
    
    @Override
    protected void paintComponent(Graphics g){
        Dimension size= getSize();
        g.drawImage(mCourt, 0, 0, (ImageObserver)null);

        int xPosit = (int) (size.height*(double)x/16459);
        int yPosit = (int) (size.width*(double)y/8230);
        g.setColor(Color.GREEN);
        g.drawString("x="+(xPosit*40)+" y="+(yPosit*40), 10, 20);
        g.fillRect(yPosit, size.height-xPosit, 6, 9);
        g.setColor(Color.BLACK);
        g.drawRect(0, 0, size.width-1, size.height-1);
    }
    
}
